package com.ericsson.enap.modules.backup.job;

import com.ericsson.common.quartz.job.MainJob;
import com.ericsson.common.quartz.job.ManualQuartzJob;
import com.ericsson.common.quartz.service.QuartzTableManager;
import com.ericsson.common.util.LogFileName;
import com.ericsson.common.util.LoggerUtils;
import com.ericsson.enap.modules.backup.task.ImsDataBackupTask;
import org.quartz.DisallowConcurrentExecution;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * @description: ims 网元备份功能主方法入口
 * @author: wangjingshi
 * @create: 2021-05-31 16:16
 */

@Component
public class ImsDataBackupJob implements MainJob {

    private Logger log = LoggerUtils.Logger(LogFileName.ImsDataBackupJob);

    @Autowired
    private QuartzTableManager quartzTableManager;
    @Autowired
    private ImsDataBackupTask imsDataBackupTask;

    /**
     * 1:执行默认备份，备份backup软件，syslog,consoleLog,safLog
     * 2:备份大文件，C-diameter Log，Additional vDicos Logs
     * 3:备份周期不同文件，logdump
     * 4:备份config、history、last
     */
    @Override
    public void doTask() {
        int jobNo = 1;
        String jobName = "ImsDataBackupTask"+jobNo;
        imsDataBackupTask.setJobNo(jobNo);
        //定时任务每天早上4点执行一次
        String cron = "";
        switch(jobNo){
            case 1:  cron = "0 0 4 * * ?";break;
            case 2:  cron = "0 0 0 * * ?";break;
            case 3:  cron = "0 29/30 * * * ?";break;
            case 4:  cron = "0 0 3 * * ?";break;
        }
        //String cron = (jobNo == 3)?"0 0 0/1 * * ?":"0 0 4 * * ?";
        log.info("======= jobNo:"+jobNo+" ======= cron:"+cron);
        System.out.println(cron);
        imsDataBackupTask.execute();
        /*quartzTableManager.addManualTaskJob(jobName,jobName,
                jobName,jobName,
                ManualQuartzJob.class,cron,imsDataBackupTask);*/
    }

}
